/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-05-22 16:59:23
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-18 15:59:02
 */
import React, { Component, Fragment } from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { Button } from 'antd';
import { WeaReqTop, WeaLeftRightLayout, WeaTree, WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

@inject('odocPrintMouldStore')
@observer
class OdocPrintMould extends Component {
  constructor(props) {
    super(props);
    const { requestName } = this.props.location.query;
    this.state = {
      requestName,
    };
  }

  componentDidMount() {
    const { odocPrintMouldStore } = this.props;
    const { officeType, isIE, requestid, workflowid, selectValue, printMouldid, requestName, signFilterlogids } = this.props.location.query;
    odocPrintMouldStore.getOdocIframe(officeType, isIE, requestid, workflowid, selectValue, printMouldid, signFilterlogids);
    odocPrintMouldStore.getMouldList(selectValue, workflowid);
    document.title = `${getLabel('513622', '打印呈批表')}:${requestName}`;
  }

  render() {
    const { odocPrintMouldStore, location } = this.props;
    const { iframeSrc, printIframe } = odocPrintMouldStore;
    const btns = location.query.officeType == 'wpsEditor' ? []
      : [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@4na4i8@print`} type="primary" onClick={() => printIframe()}>{getLabel('257', '打印')}</Button>];

    return (
      <div className="odocPrintMouldPage">
        <WeaReqTop ecId={`${this && this.props && this.props.ecId || ''}_WeaReqTop@wk1h17`}
          title={<span style={{ color: '#333' }}>{`${getLabel('513622', '打印呈批表')}:${this.state.requestName}`}</span>}
          icon={<i className="icon-coms-official" />}
          iconBgcolor="rgb(241, 74, 45)"
          buttons={btns}
        >
          <div style={{ height: '100%', borderRight: '1px solid #eaeaea' }} >
            <WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@i7z7et`}
              leftWidth={230}
              leftCom={this.getModleList()}
            >
              <div className="odocPrintIframe">
                <iframe className="req-printOdocMould" src={iframeSrc} style={{ border: 0, width: '100%', height: '100%' }} title="req-printOdocMould" />
              </div>
            </WeaLeftRightLayout>
          </div>
        </WeaReqTop>
      </div>
    );
  }

  getModleList() {
    const { odocPrintMouldStore } = this.props;
    const { treeDatas, getOtherMould, selectedKeys } = odocPrintMouldStore;
    return (
      <Fragment ecId={`${this && this.props && this.props.ecId || ''}_Fragment@lvrtas`}>
        <div className="title">
          <span>{getLabel('', '选择打印模板')}</span>
        </div>
        <WeaTree ecId={`${this && this.props && this.props.ecId || ''}_WeaTree@tuglbo`}
          datas={toJS(treeDatas)}
          // hasRadio={true}
          selectedKeys={toJS(selectedKeys)}
          renderNode={node => <span title={node.name}>{node.name}</span>}
          onSelect={getOtherMould}
        />
      </Fragment>
    );
  }
}

export default OdocPrintMould;
